package robotleMvc.frameworks.lightscene
{
	import _Pan3D.base.Camera3D;
	import _Pan3D.base.Focus3D;
	import _Pan3D.core.MathCore;
	import _Pan3D.display3D.Display3DContainer;
	import _Pan3D.program.Program3DManager;
	
	import _me.Scene_data;
	
	import com.adobe.utils.PerspectiveMatrix3D;
	
	import flash.display3D.Context3D;
	import flash.display3D.Context3DBlendFactor;
	import flash.display3D.Context3DCompareMode;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Context3DTriangleFace;
	import flash.display3D.Program3D;
	
	import org.robotlegs.mvcs.Actor;
	
	import test.vo.uvMove.UvMoveShader;
	
	public class LightsceneModel extends Actor
	{
		private var display3DContainer:Display3DContainer;
		private var context3D:Context3D;
		public function LightsceneModel()
		{
			super();
		}
		public function initData(_context3D:Context3D):void
		{
			context3D=_context3D;
			display3DContainer=new Display3DContainer();
			addUvMove0();
			
			var treeShaderProgram3d:Program3D =  Program3DManager.getInstance().getProgram(UvMoveShader.UVMOVE_SHADER);
			display3DContainer.setProgram3D(treeShaderProgram3d);
			
		}
		private function addUvMove0():void
		{
			var display3DSprite:LightUvDisplay3DSprite =new LightUvDisplay3DSprite(context3D);
			display3DSprite.url ="lightpic";
			display3DSprite.x=0;
			display3DSprite.y=0;
			display3DSprite.z=0;
			display3DSprite.scale=1;
			display3DContainer.addChild(display3DSprite);
		}
		public function updata(_context3D:Context3D):void
		{
			
			//先复制作镜头。。
			var tempCam3D:Camera3D=Scene_data.cam3D.clone();
			var fous3D:Focus3D=Scene_data.focus3D.cloneFocus3D();
			Scene_data.cam3D.distance=1000;
			fous3D.x=0
			fous3D.y=0
			fous3D.z=0
			fous3D.angle_x=-90;
			fous3D.angle_y=0;
			
			MathCore._catch_cam(Scene_data.cam3D, fous3D);
			
			context3D.setRenderToTexture(Scene_data.sceneLightText, false, 16, 0);
			context3D.clear(0.2, 0.2, 0,1);
			
			var _projMatrix:PerspectiveMatrix3D=new PerspectiveMatrix3D();
			_projMatrix.perspectiveFieldOfViewLH(1, 600/1024, 0.1, 3000);
			context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, _projMatrix, true);
			
			Scene_data.context3D.setCulling(Context3DTriangleFace.NONE);
			context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ZERO);
			context3D.setDepthTest(true, Context3DCompareMode.LESS);
			
			display3DContainer.update();
			
			//context3D.present();
			context3D.setRenderToBackBuffer();

			
			Scene_data.cam3D=tempCam3D;
		}
	}
}